package cn.schoolwow.starter.quickdao.test;

import cn.schoolwow.quickdao.transaction.Transaction;
import cn.schoolwow.starter.quickdao.QuickDAOTransactionHolder;
import cn.schoolwow.starter.quickdao.test.entity.Address;
import cn.schoolwow.starter.quickdao.test.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class DAOService {
    @Transactional(rollbackFor = Exception.class)
    public void update() throws Exception {
        Transaction transaction = QuickDAOTransactionHolder.getTransaction();

        User user = new User();
        user.setUsername("quickdao");
        user.setPassword("123456");
        int effect = transaction.insert(user);
        System.out.println(effect);

        Address address = new Address();
        address.setUserId(user.getId());
        address.setAddress("BeiJing");
        effect = transaction.insert(address);
        System.out.println(effect);
    }
}
